﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DataLayerAgent;
using System.Data.SqlClient;
using System.Data;
using XunPan.Web.Globals;
using SalePartial.Utility;
using SalePartial.Model;
using SalePartial.IDAL;

namespace SalePartial.SQLServerDAL
{
    public class XPCompanyProduct : IXPCompanyProduct
    {
        // Methods
        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int Delete(Guid ProductID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("ProductID", ProductID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductDelete]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteByCompanyID(Guid CompanyID)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductsDeleteByCompanyID]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Delete)> _
        public int DeleteDynamic(string v_whereCondition)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("WhereCondition", v_whereCondition) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductsDeleteDynamic]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Insert)> _
        public int Insert(XPCompanyProductInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("ProductID", info.ProductID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("ProductName", info.ProductName),
			new SqlParameter("ProductDescription", info.ProductDescription),
			new SqlParameter("ProductPhotoTitle", info.ProductPhotoTitle),
			new SqlParameter("ProductPhotoFile", info.ProductPhotoFile),
			new SqlParameter("CreateUserID", info.CreateUserID),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("LastUpdateDate", info.LastUpdateDate),
			new SqlParameter("ModerateStatus", info.ModerateStatus),
			new SqlParameter("ModerateDate", info.ModerateDate),
			new SqlParameter("ModerateUserID", info.ModerateUserID),
			new SqlParameter("Comments", info.Comments)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductInsert]", parameters, RowsAffected);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectAll()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductsSelectAll]", parameters, "XPCompanyProduct_All");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public  DataSet SelectByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductsSelectByCompanyID]", parameters, "XPCompanyProduct_ByCompanyID");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectDynamic(string v_whereCondition, string v_orderByExpression)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("WhereCondition", v_whereCondition),
			new SqlParameter("OrderByExpression", v_orderByExpression)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductsSelectDynamic]", parameters, "XPCompanyProduct_Dynamic");
        }

        //<DataObjectMethod(DataObjectMethodType.Fill)> _
        public DataSet SelectPaged()
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[0];
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductsSelectPaged]", parameters, "XPCompanyProduct_Paged");
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReader(Guid ProductID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("ProductID", ProductID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductSelect]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public SqlDataReader SelectReaderByCompanyID(Guid CompanyID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("CompanyID", CompanyID) };
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductsSelectByCompanyID]", parameters);
        }

        //<DataObjectMethod(DataObjectMethodType.Select)> _
        public DataSet SelectSingle(Guid ProductID)
        {
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] { new SqlParameter("ProductID", ProductID) };
            DataSet ds = dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductSelect]", parameters, "XPCompanyProduct_Single");
            DataTable dt = ds.Tables["XPCompanyProduct_Single"];
            return ds;
        }

        //<DataObjectMethod(DataObjectMethodType.Update)> _
        public int Update(XPCompanyProductInfo info)
        {
            int RowsAffected = 0;
            DbObject dbo = new DbObject(GlobalSetting.ConnectionString);
            SqlParameter[] parameters = new SqlParameter[] {
			new SqlParameter("ProductID", info.ProductID),
			new SqlParameter("CompanyID", info.CompanyID),
			new SqlParameter("ProductName", info.ProductName),
			new SqlParameter("ProductDescription", info.ProductDescription),
			new SqlParameter("ProductPhotoTitle", info.ProductPhotoTitle),
			new SqlParameter("ProductPhotoFile", info.ProductPhotoFile),
			new SqlParameter("CreateUserID", info.CreateUserID),
			new SqlParameter("CreateDate", info.CreateDate),
			new SqlParameter("LastUpdateDate", info.LastUpdateDate),
			new SqlParameter("ModerateStatus", info.ModerateStatus),
			new SqlParameter("ModerateDate", info.ModerateDate),
			new SqlParameter("ModerateUserID", info.ModerateUserID),
			new SqlParameter("Comments", info.Comments)
		};
            return dbo.RunProcedure("[dbo].[xunpan_XPCompanyProductUpdate]", parameters, RowsAffected);
        }
    }
}
